<!DOCTYPE html>
<html class="Content">
<head>
    <title>xUnit.js: Facts &amp; Fixtures</title>
    <link type="text/css" rel="Stylesheet" href="../../Style/documentation.css" />
</head>
<body>
    <h1>Facts &amp; Fixtures</h1>
    <p>
        The xUnit.js console runner uses the xUnit.js.Attributes test engine. In this way, fact and fixture registration can be kept with the target method; and is
        accomplished with C# style attribute notation:
        <span class="Code">
Function.RegisterNamespace("Test");

<strong>[Fixture]</strong>
Test.SampleFixture=function(){

    <strong>[Fixture]</strong>
    function NestedFixture(){

        <strong>[Fact]</strong>
        function NestedFact(){
            // Arrange
            var expected="expected";

            // Act
            var actual=expected;

            // Assert
            Assert.Equal(expected,actual);
        }

    }

}        
        </span>
    </p>
    <p>
        The above example will produce two fixtures: <em>Test.SampleFixture</em>, and <em>Test.SampleFixture.NestedFixture</em>; and one fact: <em>Test.SampleFixture.NestedFixture.NestedFact</em>.
    </p>
    <p>
        To avoid collisions, it is recommended to use namespaces for top level fixtures, as indicated above:
        <span class="Code">
<strong>Function.RegisterNamespace("Test");</strong>

[Fixture]
<strong>Test</strong>.SampleFixture=function(){

    [...]

}
        </span>
    </p>
    <p>
        Methods decorated with <strong>Fixture</strong> attibutes are executed when the file or script it is contained in is loaded. When the method executes, nested fixtures and facts
        will be identifed and registered, and nested fixtures will also be executed, continuing the registration chain. This is important, as it can cause unintended side effects when dealing
        with variables and execution patterns local to the scope or closure of the fixture. In other words, local code inside a fixture is <em>not</em> equivalent to <em>Setup</em> 
        and <em>Teardown</em>.
    </p>
    <p>
        Methods decorated with <strong>Fact</strong> attributes are only executed when a test run begins. This will occur after all initial script files are loaded, and any targets or traits
        have been parsed, and matching tests collected.
    </p>
</body>
</html>